package com.drugmanage.controller;

import com.drugmanage.Base.BaseController;
import com.drugmanage.annotations.Pms;
import com.drugmanage.entity.Drug;
import com.drugmanage.model.ResultInfo;
import com.drugmanage.query.DrugQuery;
import com.drugmanage.service.IDrugService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Map;

@Controller
@RequestMapping("user/drug")
public class DrugController extends BaseController{

    @Resource
    private IDrugService drugService;

    @RequestMapping("index")
    public String index(){
        return "drug";
    }

    public void save(Drug drug){
        drugService.insertDrug(drug);
    }

    @RequestMapping("queryDrugByParams")
    @ResponseBody
    @Pms(acl = "1010")
    public Map<String,Object> queryDrugByParams(DrugQuery drugQuery){
        return drugService.queryForPage(drugQuery);
    }

    @RequestMapping("savedrug")
    @ResponseBody
    @Pms(acl = "101001")
    public ResultInfo saveDrug(Drug drug){
        drugService.insertDrug(drug);
        return  success("添加成功");
    }

    @RequestMapping("deletedrugs")
    @ResponseBody
    @Pms(acl = "101003")
    public ResultInfo deleteDrugs(Integer[] ids){
        drugService.deleteDrugs(ids);
        return success("删除成功");
    }

    @RequestMapping("updatedrug")
    @ResponseBody
    @Pms(acl = "101002")
    public ResultInfo updateDrug(Drug drug){
        drugService.updateDrug(drug);
        return success("更新成功");
    }
}
